package com.example.demo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Slf4j
@Aspect
@Component
public class TimeAspect {
    /**
     * 记录⽅法耗时
     */
    //@Around("execution(* com.example.demo.controller.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        //记录⽅法执⾏开始时间
        long begin = System.currentTimeMillis();
        //执⾏原始⽅法
        Object result = pjp.proceed();
        //记录⽅法执⾏结束时间
        long end = System.currentTimeMillis();
        //记录⽅法执⾏耗时
        log.info(pjp.getSignature() + "执⾏耗时: {}ms", end - begin);
        return result;
    }
}
